package com.yr.ryjk.doctor.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.yr.ryjk.doctor.entity.Doctor;
import com.yr.ryjk.doctor.vo.CensusVO;
import com.yr.ryjk.doctor.vo.DoctorVO;
import com.yr.ryjk.doctor.vo.DoctorVOCensus;
import com.yr.ryjk.doctor.vo.TotalCensusVO;

public interface DoctorMapper {
    int deleteByPrimaryKey(String id);

    int insert(Doctor record);

    int insertSelective(Doctor record);

    Doctor selectByPrimaryKey(String id);
    
    int updateByPrimaryKeySelective(Doctor record);

    int updateByPrimaryKey(Doctor record);

    @Select("select * from doctor where phone=#{0}")
    @ResultMap("BaseResultMap")
	Doctor selectByPhone(String phone);

    @Update("update doctor set last_login_time=#{0} where phone=#{1}")
	void updateLoginTime(Date date, String phone);

    @Update("update doctor set password=#{1} where phone=#{0}")
	void updatePasswordByPhone(String phone, String passwordMd5);

	DoctorVO selectVoById(String id);

	@Update("update doctor set coin=#{0},coin_md5=#{1},total_gain_coin=#{2} where id=#{3}")
	void updateCoinById(int newCoin,String coinMd5,int totalGainCoin,String id);
	
	@Update("update doctor set scan_times=(scan_times+1) where id=#{0}")
	void updateIncreaseScanTimes(String doctorId);

	CensusVO selectCensus(String phone);

	List<DoctorVO> selectByType(@Param("pageNo") int pageNo,
			@Param("pageSize") int pageSize,
			@Param("typeId") String typeId,
			@Param("name") String name,
			@Param("phone") String phone);
	Integer selectByTypeCount(@Param("typeId") String typeId,
			@Param("name") String name,
			@Param("phone") String phone);

	@Update("update doctor set ask_price=#{0} where phone=#{1}")
	void updateAskPriceByPhone(int askPrice, String phone);

	List<Doctor> selectOfPage(int start, int limit, @Param("name")String name, @Param("phone")String phone, @Param("isDown")String isDown);
	int selectCount( @Param("name")String name, @Param("phone")String phone, @Param("isDown")String isDown);

	//按关键字搜索医生
	List<DoctorVO> selectSearch(Map<String, Object> params);
	int selectCountSearch(Map<String, Object> params);
	//已放弃
	List<DoctorVO> selectByKeyword(String keyword, String phone, int start,int pageSize);
	int selectCountByKeyword(String keyword);

	//按部门查找医生
	List<DoctorVOCensus> selectByDepartment(Map<String, Object> params);
	int selectCountByDepartment(Map<String, Object> params);

	//按名医分类查找医生
	List<DoctorVOCensus> selectDoctorVOCensusByTypeId(Map<String, Object> params);
	int selectCountDoctorVOCensusByDocId(Map<String, Object> params);

	TotalCensusVO selectTotalVoById(String docId);
	
	@Update("update doctor set is_down=#{isDown,jdbcType=INTEGER}  where id=#{docId,jdbcType=CHAR}")
	void updateDoctorById(@Param("docId")String docId,@Param("isDown")int isDown);
	
}